package com.lanou.sfu.songforu.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.sfu.songforu.R;
import com.lanou.sfu.songforu.entity.ArtistDetailAlbumEntity;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by dllo on 15/10/30.
 */
public class ArtistDetailAlbumAdapter extends BaseAdapter {
    private Context mContext;
    private List<ArtistDetailAlbumEntity.AlbumlistEntity> datas;

    public ArtistDetailAlbumAdapter(Context context, List<ArtistDetailAlbumEntity.AlbumlistEntity> lists) {
        mContext = context;
        datas = lists;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public ArtistDetailAlbumEntity.AlbumlistEntity getItem(int position) {
        if (datas != null && datas.size() > 0) {
            return datas.get(position);
        } else {
            return null;
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.artist_detail_album_listview_item, null);
            holder.imageView = (ImageView) convertView.findViewById(R.id.artist_detail_album_item_pic);
            holder.name = (TextView) convertView.findViewById(R.id.artist_detail_album_item_textView);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        ArtistDetailAlbumEntity.AlbumlistEntity albumlistEntity = getItem(position);
        if (albumlistEntity != null) {
            holder.name.setText(albumlistEntity.getTitle());
            if (albumlistEntity.getPic_big() != null) {
                Picasso.with(mContext).load(albumlistEntity.getPic_big()).into(holder.imageView);
            }
        }
        return convertView;
    }

    public class ViewHolder {
        private ImageView imageView;
        private TextView name;
    }

}
